package com.inpion.biz.dataStorage.test;

import com.inpion.biz.dataStorage.ConfigDocumentIsNotFoundException;
import com.inpion.biz.dataStorage.ConnectionIsNotDefinedException;
import com.inpion.biz.dataStorage.DataMetaInfo;
import com.inpion.biz.dataStorage.DataRecord;
import com.inpion.biz.dataStorage.DataResult;
import com.inpion.biz.dataStorage.DataServiceJob;
import com.inpion.biz.dataStorage.DataStorage;
import com.inpion.biz.dataStorage.Parameters;
import com.inpion.biz.dataStorage.FieldInfo;
import com.inpion.biz.dataStorage.QueryIdIsNotDefineException;
import com.inpion.biz.dataStorage.QueryIsNotDefinedException;
import com.inpion.biz.dataStorage.TargtHandlerClassIsNotDefinedException;

public class DataStorageServiceTestCase {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		
		 	
		// new storage instance with config path
		DataStorage storage = DataStorage.newInstance("C:/Users/john/workspaces/bizBroker.0.0.0.1/BizBrokerDataStorageBusiness/config/DataStorageBusinessConfig.xml");
		
		// define job object
		DataServiceJob job = new DataServiceJob("data.storage.cassandra");
		
		// define mapping value object
		Parameters dataValue = new Parameters();		// access parameter value
//		dataValue.put("COMMAND_NAME", "sample");
		dataValue.putNoWithQuotes("COMMAND_NAME", "SELECT");
		dataValue.putNoWithQuotes("TABLE_NAME", "TAB");
		
		// define storage target
		job.setQueryId("cassandra.query.select.user"); 			// define query id		
		job.setParameters(dataValue);  					// define mapping value
		
		try {
			DataResult result = storage.execute(job);
			DataMetaInfo meta = result.getDataMetaInfo();
			
			for (DataRecord record : result){
				for(String keyString : meta.keySet()){
					FieldInfo info = meta.get(keyString);
					String fieldName = info.getName();
					String fieldValue = (String) record.get(fieldName);
					
					System.out.println("[" + fieldName + "] : [" + fieldValue + "]");
				}
			}
			
			
		} catch (ConfigDocumentIsNotFoundException e) {
			e.printStackTrace();
		} catch (QueryIsNotDefinedException e) {
			e.printStackTrace();
		} catch (QueryIdIsNotDefineException e) {
			e.printStackTrace();
		} catch (TargtHandlerClassIsNotDefinedException e) {
			e.printStackTrace();
		} catch (ConnectionIsNotDefinedException e) {
			e.printStackTrace();
		}
		
	}
		
}
